package com.CGFrame.struts.bean.reguser;

import java.util.Iterator;
import java.util.LinkedHashSet;


import com.CGFrame.struts.POJOs.Employee;
import com.CGFrame.struts.POJOs.Reguser;
import com.CGFrame.struts.POJOs.Task;
import com.CGFrame.struts.bean.MD5;
import com.CGFrame.struts.bean.ProjectOperate;
import com.CGFrame.struts.bean.ProjectOperateFactory;
import com.CGFrame.struts.bean.task.TaskBean;

public class ReguserBean {
	private Reguser reguser;
	private ProjectOperate pop = ProjectOperateFactory.getprojectOperate();
	
	public ReguserBean(String regUserId)
	{
		this.reguser = (Reguser)pop.UniqueQuery("Reguser", "regUserId,"+regUserId);
	}
	public LinkedHashSet getTasksByProject(String projectId)
	{
		LinkedHashSet<Task> set = new LinkedHashSet<Task>();
		Iterator ite_Tasks = this.reguser.getTasks().iterator();
		while(ite_Tasks.hasNext())
		{
			Task task = (Task)ite_Tasks.next();
			TaskBean taskBean = new TaskBean(task);
			if ( taskBean.getProjectId().toString().equals(projectId)){
				set.add(task);
			}
		}
		return set;
	}
	
	public String getEmpNameByReguserId(){
		return reguser.getEmployee().getEmpName();
		
	}
	public String getReguserName(){
		return reguser.getRegName();
	}
	public Employee getEmployee()
	{
		return reguser.getEmployee();
	}
	public Reguser getReguser() {
		return this.reguser;
	}
	public void setPassWord(String pw)
	{
		MD5 m = new MD5();
		String passWord = m.getMD5ofStr(pw);
		reguser.setPassWord(passWord);
		pop.saveObject(reguser);
	}
	
}
